const util = require('../../utils/util');
const request = require('../../utils/request')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: '',
        navbarHeight: 0,
        scrollTop: 0,
        userInfo: null,

        isStoreIds: false, //是否是店员，--展示核销台
        navlist: [{
                name: '待付款',
                img: '/pages/images/my-menu.png',
                type: 'payment',
                num: 0
            },
            {
                name: '待出库',
                img: '/pages/images/my-menu2.png',
                type: 'chuku',
                num: 0
            },
            {
                name: '待配送',
                img: '/pages/images/my-menu3.png',
                type: 'undelivered',
                num: 0
            },
            {
                name: '待收货',
                img: '/pages/images/my-menu4.png',
                type: 'confirm',
                num: 0
            },
            {
                name: '退款/售后',
                img: '/pages/images/my-menu5.png',
                type: 'aftersale',
                num: 0
            },
        ],
        showScore: false,
        peisong_count:{
          undelivered: 0,
          aftersale_qujian: 0
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            navbarHeight: util.getNavbarHeight(),
            userInfo: wx.getStorageSync('userInfo'),
            baseUrl: request.BASE_URL 
        })
        //改变头部电量条背景色
        wx.setNavigationBarColor({
            frontColor: '#ffffff',
            backgroundColor: '#ffffff',
        })
        this.getList()
    },
    onShow() {
        this.getUserInfo()
        this.getOrderCount()
        getApp().globalData.isCenter = true
    },
    hideClose(e){
      let isNew = e.detail || false
      this.setData({
        showScore: !this.data.showScore
      })
      if(isNew){
        this.getUserInfo()
      }
    },
    getOrderCount(){
      let _this = this 
      request._post('/api?method=order.order_count',{}).then(res=>{
          console.log(res,111)
          let navlist = _this.data.navlist
          navlist[0].num = res.data.user_count.payment || 0
          navlist[1].num = res.data.user_count.chuku || 0
          navlist[2].num = res.data.user_count.store_chukued || 0
          navlist[3].num = res.data.user_count.confirm || 0
          navlist[4].num = res.data.user_count.aftersale || 0
          console.log(navlist)
          _this.setData({
            navlist,
            peisong_count: res.data.peisong_count
          })
      })
    },
    getList() {
      let _this = this 
      request._post('/api?method=user.userHelp',{}).then(res=>{
          console.log(res,111)
          _this.setData({
              list:res.data.help,
              service_hotline:res.data.service_hotline,
              shop_default_image:res.data.shop_default_image
          })
          _this.data.list.forEach(function(obj,index) {
              obj.isShow = false
          })
      })
  },
    onPageScroll(e) {
        this.setData({
            scrollTop: e.scrollTop,
        });
    },
    // 我的积分
    tointegral() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/integral/integral'
        })
    },
    showContactTap(){
      this.setData({
        showContact: !this.data.showContact
      })
    },
    /**
     * 跳转我的订单
     */
    allOrder(e) {
        let type = e.currentTarget.dataset.type
        let url = ''
        if (type == 'aftersale') {
            wx.navigateTo({
                url: '/pages/mine/pages/my/afterSaleorder/afterSaleorder'
            })
        } else {
            wx.navigateTo({
                url: '/pages/mine/pages/my/all-orders/all-orders?status=' + type,
            })
        }


    },
    toSetting() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/set-up/set-up'
        })
    },

    /**
     * 收货地址
     */
    receivingAddress() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/my-address/my-address',
        })
    },

    /**
     *常见问题 
     */
    problem() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/problem/problem',
        })
    },


    /**
     *我的钱包 
     */
    wallet() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/my-wallet/my-wallet',
        })
    },
    getTgm() {
        wx.navigateTo({
            // url: '/pages/mine/pages/my/share-poster/share-poster',
          url:'/pages/mine/pages/my/share/index'
        })
    },


    /**
     *优惠券 
     */
    coupon() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/my-coupon/my-coupon',
        })
    },

    /**
     *核销台 
     */
    verificationDesk() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/verification-desk/verification-desk',
        })
    },


    /**
     *红包补贴 
     */
    join() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/store-entry/store-entry',
        })
    },

    /**
     *礼品卡充值 
     */
    rechage() {
        wx.navigateTo({
            // url: '/pages/mine/pages/my/rechage-page/rechage-page',
            url: '/pages/mine/pages/my/my-wallet/my-wallet'
        })
    },

    /**
     *取货码 
     */
    pickUp() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/pickUp-center/pickUp-center',
        })
    },
    // 添加银行卡
    toBankCard() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/bankcard/bankcard',
        })
    },
    toAfterSale() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/afterSales/afterSales',
        })
    },
    commisson() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/commission/commission',
        })
    },
    orderMenger() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/ordermange/ordermange',
        })
    },
    /**
     *个人资料 
     */
    personal() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/personal-data/personal-data',
        })
    },

    /**
     *设置 
     */
    setUp() {
        wx.navigateTo({
            url: '/pages/mine/pages/my/set-up/set-up',
        })
    },

    // 获取个人信息
    getUserInfo() {
        let _this = this
        request._get('/api?method=user.info', {}, 'noload').then(res => {
            _this.setData({
                userInfo: res.data,
                isStoreIds: res.data.store_ids.length > 0 ? true : false
            })
           
            
        })
    },



})